#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <sys/socket.h>
#include <arpa/inet.h>
#include <netinet/in.h>
#include <iostream>

using namespace std;

int main(){
    /*
     * 1.创建侦听套接字
     * 2.绑定
     * 3.监听
     * */
    int sockfd = socket(AF_INET, SOCK_STREAM, 0);
    if(sockfd < 0){
        perror("listen_fd");
        return 0;
    }
    
    struct sockaddr_in addr;
    addr.sin_family = AF_INET;
    addr.sin_port = htons(38989);
    addr.sin_addr.s_addr = inet_addr("10.0.16.3");


    int ret = connect(sockfd, (struct sockaddr*)&addr, sizeof(addr));
    if(ret < 0){
        perror("connect");
        return 0;
    }
    while(1){
        char buf[1024] = "121";
       // cout << "please enter your msg# ";
       // fflush(stdout);

       // cin >> buf;
        ssize_t send_size = send(sockfd, buf, strlen(buf), 0);
        if(send_size < 0){
            continue;
        }
       //bin memset(buf, '\0', sizeof(buf));
        ssize_t  recv_size = recv(sockfd, buf, sizeof(buf) - 1, 0);
        if(recv_size < 0){
            continue;
        }
        sleep(1);
        //else if(recv_size == 0){
        //    printf("server shutdown connect\n");
        //    break;
       // }
        //printf("%s\n", buf);
    }
   
    close(sockfd);
    return 0;
}

